package cc.wfu.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
@EnableConfigurationProperties(MailConfigProperties.class)
public class MailConfig {

    @Bean
    public JavaMailSender javaMailSender(MailConfigProperties properties) {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        // 配置 JavaMailSenderImpl 对象，比如设置主机、端口、用户名、密码等
        mailSender.setPassword(properties.getPassword());
        mailSender.setPort(properties.getPort());
        mailSender.setProtocol(properties.getProtocol());
        mailSender.setUsername(properties.getUsername());
        mailSender.setHost(properties.getHost());
        return mailSender;
    }
}